<!-- 正文开始 -->
<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-card-body">
      <!-- 头部操作栏 -->
      <div class="layui-form lay-header">
        <div class="toolbar">
          <div class="layui-form-item lay-query-content">
            <div class="lay-query-box">
              <div class="query-lt">
                <div class="layui-inline">
                  <label class="layui-form-label w-auto">订单编号：</label>
                  <div class="layui-input-inline mr0">
                    <input name="sn" class="layui-input" type="text" placeholder="输入订单编号" />
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label w-auto">物料编号：</label>
                  <div class="layui-input-inline mr0">
                    <input name="skuCode" class="layui-input" type="text" placeholder="请输入物料编号" />
                  </div>
                </div>
                <div class="layui-inline">
                  <label class="layui-form-label w-auto">物料名称：</label>
                  <div class="layui-input-inline mr0">
                    <input name="productName" class="layui-input" type="text" placeholder="请输入物料名称" />
                  </div>
                </div>
              </div>
              <div class="query-rt">
                <div class="layui-inline">
                  <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog" lay-submit layui-form-keyDownSearch="true">查询</button>
                  <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置</button>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>

      <!-- 表格 -->
      <table class="layui-table" id="erpPurchaseOrderDetailTable" lay-filter="erpPurchaseOrderDetailTable"></table>
    </div>
  </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="erpPurchaseOrderDetail-table-bar">
  <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<!-- js部分 -->
<script>
  layui.use(["layer", "form", "table", "admin", "laytpl", "laydate", "util"], function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var config = layui.config;
    var admin = layui.admin;
    var upload = layui.upload;
    var laytpl = layui.laytpl;
    var laydate = layui.laydate;
    var util = layui.util;

    // 渲染表格
    var insTb = table.render({
      elem: "#erpPurchaseOrderDetailTable",
      url: config.base + "enterprise/purchase/admin/purchaseOrderDetail/list",
      where: {
        access_token: config.getToken().access_token
      },
      page: true,
      cellMinWidth: 100,
      cols: [
        [
          { type: "numbers" },
          { field: "sn", align: "center", title: "订单编号", width: 150 },
          { field: "corporateName", align: "center", title: "供应商", width: 120 },
          { field: "statusDesc", align: "center", title: "状态", width: 100 },
          { field: "skuCode", align: "center", title: "物料编号", width: 120 },
          { field: "productName", align: "center", title: "物料名称", width: 120 },
          { field: "specifications", align: "center", title: "规格型号", width: 120 },
          { field: "quantity", align: "center", title: "数量" },
          { field: "unitName", align: "center", title: "计量单位", width: 100 },
          { field: "rate", align: "center", title: "税率(%)" },
          { field: "taxPrice", align: "center", title: "含税单价" },
          { field: "price", align: "center", title: "单价" },
          {
            field: "amount",
            align: "center",
            title: "金额",
            templet: function (d) {
              return (d.totalAmount - d.tax).toFixed(6);
            }
          },
          { field: "tax", align: "center", title: "税额" },
          { field: "totalAmount", align: "center", title: "合计金额" }
        ]
      ]
    });

    // 工具条点击事件
    table.on("tool(erpPurchaseOrderDetail-table)", function (obj) {
      var data = obj.data;
      var layEvent = obj.event;
      if (layEvent === "edit") {
        // 修改
        showEditModel(data);
      } else if (obj.event === "del") {
        //删除
        doDelete(obj);
      }
    });

    //监听排序
    table.on("sort(erpPurchaseOrderDetailTable)", function (obj) {
      table.reload("erpPurchaseOrderDetailTable", {
        initSort: obj,
        where: {
          sort: obj.field,
          order: obj.type
        }
      });
    });

    // 搜索
    form.on("submit(formSubSearchLog)", function (data) {
      insTb.reload({ where: data.field, page: { curr: 1 } }, "data");
    });

    // 重置搜索
    form.on("submit(resets)", function (data) {
      $(".lay-header").find("select").val("");
      $(".lay-header").find("input").val("");
      let field = data.field;
      for (let key in field) {
        field[key] = "";
      }
      insTb.reload({ where: field, page: { curr: 1 } }, "data");
    });

    // 导出excel
    $("#erpPurchaseOrderDetailBtnExport").click(function () {
      var checkRows = table.checkStatus("erpPurchaseOrderDetailTable");
      if (checkRows.data.length == 0) {
        layer.msg("请选择要导出的数据", { icon: 2 });
      } else {
        table.exportFile(insTb.config.id, checkRows.data, "xls");
      }
    });
  });
</script>
